package com.outlook.flowervow;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

public class EventInventory implements Listener {
    private Main plugin;
    public EventInventory(Main plugin){
        this.plugin = plugin;
    }
    @EventHandler
    public void event(InventoryClickEvent e){
        Player p = (Player) e.getWhoClicked();
        if (e.getView().getTitle().equalsIgnoreCase(ChatColor.GREEN + "TeaBane Menu")){
            e.setCancelled(true);
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD+"》经典BedWars起床战争")){
               BungeeTP(Main.instance.getConfig().getString("Server.Bedwars"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED+"》多人乱斗PVPFFA模式"+ChatColor.GREEN+"TeaBane团队原创插件")){
                BungeeTP(Main.instance.getConfig().getString("Server.FFA"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA+"》Bridge搭路练习(大佬专场)"+ChatColor.GREEN+" HOT!")){
                BungeeTP(Main.instance.getConfig().getString("Server.Bridge"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE+"》Rush击退起床"+ChatColor.GREEN+"TeaBane团队原创插件")){
                BungeeTP(Main.instance.getConfig().getString("Server.Rush"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED+"》Duel单挑PVP竞技场")){
                BungeeTP(Main.instance.getConfig().getString("Server.PVP"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN+"》趣味生存合集")){
                BungeeTP(Main.instance.getConfig().getString("Server.Survival"),p);
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN+"》点击回到主大厅")){
                BungeeTP(Main.instance.getConfig().getString("Server.Hub"),p);
            }
        }

    }
    public void BungeeTP(String server,Player p){
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("Connect");
            out.writeUTF(server);
            p.sendPluginMessage(plugin,"BungeeCord", out.toByteArray());

    }
}
